cmake_minimum_required(VERSION 3.5)

project(ndebug)


option(RUN_DEBUG "compile with debug" OFF)
option(RUN_CMAKE_RELEASE "compile with CMAKE Release" OFF)
set(optimize "-O2 -DNDEBUG")

if(RUN_DEBUG)
    set(CMAKE_BUILD_TYPE Debug)
elseif(RUN_CMAKE_RELEASE)
    # release 版本会自动定义  NDEBUG
    set(CMAKE_BUILD_TYPE Release)
else()
    set(CMAKE_CXX_FLAGS "${optimize}")
    set(CMAKE_C_FLAGS "${optimize}")
    message(STATUS "${CMAKE_CXX_FLAGS}")
    message(STATUS "${CMAKE_C_FLAGS}")
endif()

set(
    exe_source
    ndebug.cpp
)

set(exe_name "ndebug.out")

add_executable(${exe_name}  ${exe_source})


# 如果是编译release版本的话，
# mkdir Release
# cd Release
# cmake -DCMAKE_BUILD_TYPE=Release ..
# make

# 如果是编译debug版本的话，
# mkdir Debug
# cd Debug
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make

